//引入util js
var _util = require('util/util.js');

//account_service
var _catalog_service = {
    getallitems : function(pagesize,pageid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/items/pages/" +pagesize+"/"+pageid+"?sortby=1"),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
    getitemby : function(itemOrshopname,product,pagesize,pageid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/items/"+itemOrshopname+"/"+product+"/pages/"+pagesize+"/"+pageid+"?sortby=1"),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
    getAlloneclass : function(resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/categories"),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
    gettwoclassbyone : function(categoryid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/categories/"+categoryid),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
    getitemsbytwo : function(productid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/categories/products/"+productid+"?sortby=1"),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
    additem : function(newitem,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/items"),
            data    : newitem,
            method  : 'POST',
            success : resolve,
            error   : reject,
        })
    },
    edititem : function(newitem,itemid,resolve,reject){
        console.log("xixiaa")
        console.log(newitem)
        _util.request({
            url     : _util.getServerURL("/admin/catalog/items/"+itemid),
            data    : newitem,
            method  : 'PUT',
            success : resolve,
            error   : reject,
        });
    },
    deleteitem : function(resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/items/"+itemid),
            method  : 'DELETE',
            success : resolve,
            error   : reject,
        });
    },
    editoneclass : function(category,categoryid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/categories/"+categoryid),
            data    : category,
            method  : 'PUT',
            success : resolve,
            error   : reject,
        });
    },
    addoneclass : function(category,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/categories"),
            data    : category,
            method  : 'POST',
            success : resolve,
            error   : reject,
        });
    },
    edittwoclass : function(product,productid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/products/"+id),
            data    : product,
            method  : 'PUT',
            success : resolve,
            error   : reject,
        });
    },
    addtwoclass : function(product,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/products"),
            data    : product,
            method  : 'POST',
            success : resolve,
            error   : reject,
        });
    },
    getAllattrnames : function(resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/attr"),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
    getAllattrvalues : function(attrid,resolve,reject){
        _util.request({
            url     : _util.getServerURL("/admin/catalog/attrvals/"+attrid),
            method  : 'GET',
            success : resolve,
            error   : reject,
        });
    },
}

module.exports = _catalog_service;